package com.zs.leymovie.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.zs.leymovie.R;
import com.zs.leymovie.bean.Comment;

import java.util.List;

/**
 * Created by Administrator on 2015/8/19 0019.
 */
public class MovieDetailLvAdapter extends AppAdapter {
    private List<Comment> list;
    private Context context;
    private BitmapDisplayConfig config;
    private final Animation animation;
    private BitmapUtils bitmapUtils;

    public MovieDetailLvAdapter(List list, Context context) {
        super(list, context);
        this.list = list;
        this.context = context;
        config = new BitmapDisplayConfig();
        config.setLoadFailedDrawable(context.getResources().getDrawable(R.mipmap.huodng_image));
        config.setLoadingDrawable(context.getResources().getDrawable(R.mipmap.huodng_image));
        animation = AnimationUtils.loadAnimation(
                context, R.anim.home_listview_anim);
        config.setAnimation(animation);
        bitmapUtils = new BitmapUtils(context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.movie_detail_item, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        Comment comment = list.get(position);
        bitmapUtils.display(vh.detail_lv_user_image, comment.getUser_img_url(), config);
        vh.detail_lv_content.setText(comment.getContent());
        Double dRating = Double.parseDouble(comment.getScore());
        int iRating = (int) ((dRating / 2.0) * 10);
        float fRating = iRating / 10.0f;
        vh.detail_lv_ratingbar.setRating(fRating);
        vh.detail_lv_score.setText(comment.getScore() + "分");
        vh.detail_lv_user_name.setText(comment.getUser_name());
        vh.detail_lv_user_time.setText(comment.getTime());
        vh.detail_lv_user_xingzuo.setText(comment.getUser_xingzuo());
        vh.zan_num.setText(comment.getZan_num()+"");
        vh.reply_num.setText(comment.getReply_num()+"回复");
        return convertView;

    }


    private class ViewHolder {
        @ViewInject(R.id.detail_lv_user_image)
        private ImageView detail_lv_user_image;
        @ViewInject(R.id.detail_lv_user_xingzuo)
        private TextView detail_lv_user_xingzuo;
        @ViewInject(R.id.detail_lv_user_name)
        private TextView detail_lv_user_name;
        @ViewInject(R.id.detail_lv_user_time)
        private TextView detail_lv_user_time;
        @ViewInject(R.id.detail_lv_ratingbar)
        private RatingBar detail_lv_ratingbar;
        @ViewInject(R.id.detail_lv_score)
        private TextView detail_lv_score;
        @ViewInject(R.id.detail_lv_content)
        private TextView detail_lv_content;
        @ViewInject(R.id.zan_num)
        private TextView zan_num;
        @ViewInject(R.id.reply_num)
        private TextView reply_num;

        public ViewHolder(View convertView) {
            ViewUtils.inject(this, convertView);
        }
    }
}
